package br.gov.ba.mam.banco.mysql;

import java.sql.Connection;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * @author igorfs
 */
public class C3P0Pool {
	
	private static ComboPooledDataSource cpds = null;

	static {

		String driver 	= "com.mysql.jdbc.Driver";
		String url 		= "jdbc:mysql://localhost:3306/mam";
		String login 	= "root";
		String senha 	= "1234";
		
		cpds = new ComboPooledDataSource();

		try {
			
			cpds.setDriverClass(driver);
			cpds.setJdbcUrl(url);
			cpds.setUser(login);
			cpds.setPassword(senha);

			cpds.setMinPoolSize(1);
			cpds.setAcquireIncrement(2);
			cpds.setMaxPoolSize(20);
			
			cpds.setCheckoutTimeout(1800);
			cpds.setMaxStatements(20);
			cpds.setIdleConnectionTestPeriod(10);
			cpds.setNumHelperThreads(3);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public static Connection getConnection() throws Exception {
		Connection conn = cpds.getConnection();
		conn.setAutoCommit(false);
		return conn;
	}

}